<?php 
$sql2 = "SELECT  `Under 5 Yrs`, `5 to 9 Yrs`, `10 to 14 Yrs`, `15 to 19 Yrs`, `20 to 24 Yrs`, `25 to 34 Yrs`, `35 to 44 Yrs`, `45 to 54 Yrs`, `55 to 59 Yrs`, `60 to 64 Yrs`, `65 to 74 Yrs`, `75 to 84 Yrs`, `85 Yrs and Over`, `Total Population` FROM `ZipCode Profile1` as age WHERE `ZCTA5` = $zipcode";
$result2 = mysql_query($sql2,$db);
if ($result2)
{
	while ($row = mysql_fetch_array($result2,MYSQL_NUM))
	{
		$total_pop = $row[13];
	    $lessthen_5=$row[0];
		$fiveTo14= $row[1]+$row[2];
		$fifteenTo24=$row[3]+$row[4];
		$twentyfiveTo44=$row[5]+$row[6];
		$fourtyfiveTo64=$row[7]+$row[8]+$row[9];
		$sixtyfiveAndabove=$row[10]+$row[11]+ $row[12];
	}
}

if($total_pop != 0)
{
$lessthen_5_percet = number_format((100*$lessthen_5)/$total_pop,2);

$fiveTo14_percet = number_format((100*$fiveTo14)/$total_pop,2);

$fifteenTo24_percet = number_format((100*$fifteenTo24)/$total_pop,2);

$twentyfiveTo44_percet = number_format((100*$twentyfiveTo44)/$total_pop,2);

$fourtyfiveTo64_percet = number_format((100*$fourtyfiveTo64)/$total_pop,2);

$sixtyfiveAndabove_percet = number_format((100*$sixtyfiveAndabove)/$total_pop,2);

echo "<Table width=240px cellspacing='-1' bordar=0>";
      echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td >Total Population: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$total_pop;
	  echo "</td>";
	  echo "</tr>";

	  echo "<tr style='width:100%;font-size:12px'>";
	  echo "<td>Less than 5 years: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$lessthen_5." (".$lessthen_5_percet."%)";
	  echo "</td>";
	  echo "</tr>";
	  
      echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td>5 to 14 Years: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$fiveTo14." (".$fiveTo14_percet."%)";
	  echo "</td>";
	  echo "</tr>";
	  
	  echo "<tr style='width:100%;font-size:12px'>";
	  echo "<td>15 to 24 Years: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$fifteenTo24." (".$fifteenTo24_percet."%)";
	  echo "</td>";
	  echo "</tr>";
	  
      echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td>25 to 44 Years: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$twentyfiveTo44." (".$twentyfiveTo44_percet."%)";
	  echo "</td>";
	  echo "</tr>";
	  
	  echo "<tr style='width:100%;font-size:12px'>";
	  echo "<td>45 to 64 Years: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$fourtyfiveTo64." (".$fourtyfiveTo64_percet."%)";
	  echo "</td>";
	  echo "</tr>";
	  
      echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td>65 & above: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$sixtyfiveAndabove." (".$sixtyfiveAndabove_percet."%)";
	  echo "</td>";
	  echo "</tr>";
echo "</Table>";
}
else
{
$nodata_msg = "Data is not available.  Please make sure the City, State and Zipcode Information is correct.";

echo "<Table width=240px cellspacing='-1' bordar=0>";
      echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td align='right' nowrap='nowrap'>".$nodata_msg;
	  echo "</td>";

	  echo "</Table>";


}

?>